package com.ruitu.arad.util;

import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

// View相关工具
public class ViewUtils {

    public static void setVisibility(int visibility, View view) {
        if (view != null && view.getVisibility() != visibility) {
            view.setVisibility(visibility);
        }
    }

    public static void setVisibility(int visibility, View... views) {
        for (View view : views) {
            if (view != null && view.getVisibility() != visibility) {
                view.setVisibility(visibility);
            }
        }
    }

    public static String getTvTxt(TextView tv) {
        if (null == tv) {
            throw new NullPointerException("不能传入空的控件!");
        }
        return tv.getText().toString().trim();
    }

    public static boolean isTvEmpty(TextView tv) {
        if (null == tv) {
            throw new NullPointerException("不能传入空的控件!");
        }
        return TextUtils.isEmpty(tv.getText().toString().trim());
    }

    public static boolean isSlideToBottom(RecyclerView recyclerView) {

        if (recyclerView == null) return false;

        if (recyclerView.computeVerticalScrollExtent() + recyclerView.computeVerticalScrollOffset() >= recyclerView.computeVerticalScrollRange())

            return true;

        return false;

    }

}
